
package com.rt.schedulenew.utils.util;
import org.slf4j.LoggerFactory;
import java.io.File;
import org.slf4j.Logger;
public class PathUtil
{
    private static final Logger log;
    
    public static String dirPathFormate(String dirPath) {
        dirPath = dirPath.replace("\\n", "").replace("\\", "/");
        dirPath = (dirPath.endsWith("/") ? dirPath : (dirPath + "/"));
        return dirPath;
    }
    
    public static String filePathFormate(String filePath) {
        filePath = filePath.replace("\\n", "").replace("\\", "/");
        return filePath;
    }
    
    public static String getFileNameByFilePath(String filePath) {
        filePath = filePathFormate(filePath);
        if (filePath.endsWith("/")) {
            PathUtil.log.error("路径不正确，路径：{}", (Object)filePath);
            return null;
        }
        final String[] arry = filePath.split("/");
        final int len = arry.length;
        if (len > 0) {
            return arry[len - 1];
        }
        PathUtil.log.error("路径不正确，路径：{}", (Object)filePath);
        return null;
    }
    
    public static String getFileDirByFilePath(final String filePath) {
        final File file = new File(filePath);
        String parentDir = file.getParentFile().getAbsolutePath();
        parentDir = dirPathFormate(parentDir);
        return parentDir;
    }
    
    public static String getRemotePathByLocalPath(final String tempDir, final String localPath) {
        String remoteFilePath = localPath.replace(tempDir, "");
        if (remoteFilePath.startsWith("/")) {
            remoteFilePath = remoteFilePath.replaceFirst("/", "");
        }
        return remoteFilePath;
    }
    
    static {
        log = LoggerFactory.getLogger((Class)PathUtil.class);
    }
}
